<%@ page language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ include file="/commons/jsp/taglibs.jsp" %>
<%@taglib prefix="frame" uri="http://www.framework.com/taglib" %>
<html>
<head>
    <title>公共平台 </title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <!-- 样式文件的引入 -->
    <link href="${ctx}/commons/css/style.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/commons/themes/default/easyui.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/commons/themes/icon.css"/>
    <!-- jqueryUI JS文件的引入 -->
    <script type="text/javascript" src="${ctx}/commons/js/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="${ctx}/commons/js/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="${ctx}/commons/js/easyui-extends-validate.js"></script>
    <!-- jqueryUI国际化 -->
    <script type="text/javascript" src="${ctx}/commons/js/easyui-lang-zh_CN.js"></script>
    <!-- 开发使用的公用js方法 -->
    <script type="text/javascript" src="${ctx}/commons/js/common.js"></script>
    <!-- 开发国际化的引用，主要完成后台信息在前台提示的国际化，一定要放在最后 -->
    <script type="text/javascript">var ctx = '${ctx}';
    var actionExt = "action";
    var i18n = new Object();</script>
    <script src="${ctx}/commons/js/i18n/message_zh_CN.js" type="text/javascript"></script>
</head>

<body>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'west',border:true" style="width:260px;">
        <div style="padding:0;border-bottom:1px solid #ddd;width: 242px;height: 14px;background-color: #f5f5f5;text-align: center;font-size: 12px;padding: 8px;">
            机 构 树
        </div>
        <ul id="deptByUserTree"></ul>
    </div>
    <div data-options="region:'center',border:true">
        <div class="easyui-layout" data-options="fit:true,border:false">
            <div data-options="region:'north',border:false" style="padding: 4px;height: 50px;overflow: hidden;">
                <div class="easyui-panel" data-options="fit:true,border:true">
                    <div class="queryContent">
                        <form name="searchForm" id="searchUserForm" method="post" action="" style="display: none; ">
                            <table class="queryTable">
                                <tbody>
                                <tr>
                                    <th width="70%">姓名</th>
                                    <td><input class="easyui-validatebox" type="text" name="name" maxlength="20"
                                               style="width:120px"></input></td>
                                    <th>登录名称</th>
                                    <td><input class="easyui-validatebox" type="text" name="loginName" maxlength="20"
                                               style="width:120px"></input></td>
                                    <th>角色</th>
                                    <td><input id="roles" style="width:120px" class="easyui-combobox" name="roles"
                                               data-options="valueField:'id',textField:'name',url:'${ctx}/framework/role/findRoleListExcludeAdmin'"/>
                                    </td>
                                    <td align="left"><a href="javascript:void(0);" class="easyui-linkbutton"
                                                        id="searchUser" plain="true">查询</a>
                                        <a href="javascript:void(0);" class="easyui-linkbutton" id="resetSearchUser"
                                           plain="true">清空</a></td>
                                </tr>
                                </tbody>
                            </table>
                        </form>
                    </div>
                </div>
            </div>
            <div data-options="region:'center',border:false" style="padding: 4px;">
                <table id="listUserTable" class="easyui-datagrid"
                       data-options="singleSelect:false,toolbar:'#usertb',method:'post',rownumbers:true,fit:true,fitColumns:true,border:true,
					pagination:true,remoteSort:true,multiSort:true,striped:true,onLoadSuccess:function(data){$('#'+userParamObj.searchID).attr('disabled',false);},
					url:'${ctx}/framework/user/list'" }>
                    <thead>
                    <tr>
                        <th data-options="field:'id',checkbox:true"></th>
                        <th data-options="field:'name',width:40,sortable:true,formatter: function(value,row,index){
							var content;
							<c:choose>
							<c:when test="${not empty isRight}">
								content = '<a href=javascript:void(0);  onclick=openDataDialog(userParamObj,\''+row.id+'\') >'+value+'</a>';
							</c:when>
							<c:otherwise>content = value;</c:otherwise>
							</c:choose>
							return content;
							},title:'姓名'"></th>
                        <th data-options="field:'loginName',width:40,title:'单位名称(登录名)'"></th>
                        <!--<th data-options="field:'deptName',align:'center',width:80,title:'部门'"></th>-->
                        <th data-options="field:'roleName',align:'center',width:50,title:'所属角色'"></th>
                        <th data-options="field:'sexName',width:20,align:'center',title:'性别'" align="center"></th>
                        <th data-options="field:'lastLoginTime',sortable:true,width:80,title:'最后登录时间'"
                            align="center"></th>
                        <th data-options="field:'updateTime',sortable:true,width:80,title:'更新时间'" align="center"></th>
                        <th data-options="field:'operate',width:100,align:'center',title:'操作',formatter:formatOper"></th>
                    </tr>
                    </thead>
                </table>
                <div id="usertb" style="display: none;">
                    <div>
                        <c:if test="${not empty isRight}">
                            <a href="javascript:void(0);" onclick="openDataDialog(userParamObj);"
                               class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
                            <a href="javascript:void(0);" onclick="updateData(userParamObj);" class="easyui-linkbutton"
                               iconCls="icon-edit" plain="true">修改</a>
                            <a href="javascript:void(0);" onclick="deleteData(userParamObj);" class="easyui-linkbutton"
                               iconCls="icon-remove" plain="true">删除</a>
                            <!-- <a href="javascript:void(0);" onclick="rightManage();" class="easyui-linkbutton" iconCls="icon-role-menu" plain="true">权限管理</a> -->
                        </c:if>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    //初始化表格对应的js对象
    var userParamObj;
    $(function () {
        //初始化表格对象数据
        userParamObj = new initParams(
            {
                paramObjName: 'userParamObj',//表格对应的实体对象名称，好区分多个表格情况下的对象
                tableId: 'listUserTable',
                addDataFormId: 'addUserDataForm',
                showDialogId: 'firstLevelDialog',
                searchID: 'searchUser',
                resetSearchID: 'resetSearchUser',
                searchFormID: 'searchUserForm',
                updateUrl: "${ctx}/framework/user/input?id=",
                deleteUrl: '${ctx}/framework/user/remove',
                addDialogWidth: 700,
                addDialogHeight: 330,
                ctx: '${ctx}',
                addDialogTitle: '用户信息'
            });
        //初始化查询
        init(userParamObj);
        $('#deptByUserTree').tree({
            onClick: function (node) {
                var queryParams = {"deptId": node.id};
                $('#' + userParamObj.tableId).datagrid('options').queryParams = queryParams;
                $('#' + userParamObj.tableId).datagrid('reload');
            },
            url: '${ctx}/framework/dept/getDeptTree' + '?r=' + new Date().getTime(),
            method: 'get',
            animate: true,
            lines: true
        });
    });
    function bindRole() {
        var records = $('#' + userParamObj.tableId).datagrid('getSelections');
        if (records.length < 1) {
            $.messager.alert('提示', "请选择记录！", 'info');
        } else {
            var deleteIds = '';
            for (var i = 0; i < records.length - 1; i++) {
                deleteIds += records[i].id + ",";
            }
            deleteIds += records[records.length - 1].id;
            top.$('#firstLevelDialog').dialog({
                title: "绑定角色",
                iconCls: 'icon-role-menu',
                width: 500,
                height: 300,
                closed: false,
                inline: true,
                cache: false,
                href: "${ctx}/framework/user/bind-role.jsp",
                modal: true,
                buttons: [{
                    text: '确定',
                    id: 'saveEntityBt',
                    iconCls: 'icon-ok',
                    handler: function () {
                        var records = $('#roleTable').datagrid('getSelections');
                        if (records.length < 1) {
                            $.messager.alert('提示', "请选择角色！", 'info');
                        } else {
                            $.ajax({
                                type: "POST",
                                timeout: 20000,
                                url: "${ctx}/framework/user/bindRole",
                                data: {"deleteIds": deleteIds, "roleId": records[0].id},
                                success: function (data) {
                                    var msn = '' || i18n[''];
                                    msn = msn || i18n[data];
                                    if (msn == undefined) {
                                        top.$.messager.alert('提示', i18n.serverError, 'info');
                                    } else if (msn) {
                                        top.$.messager.alert('提示', msn, 'info', function () {
                                            top.$('#' + userParamObj.tableId).datagrid('reload');
                                            top.$('#firstLevelDialog').dialog('close');
                                        });
                                    }
                                },
                                error: function () {
                                    $.messager.alert('提示', i18n.requestError, 'error');
                                }
                            });
                        }
                    }
                }, {
                    text: '取消',
                    iconCls: 'icon-cancel',
                    handler: function () {
                        top.$('#firstLevelDialog').dialog('close');
                    }
                }]
            }).dialog('open');
        }
    }
    function rightManage(userId, userType) {
        top.$('#firstLevelDialog').dialog({
            title: "权限管理",
            iconCls: 'icon-role-menu',
            width: 600,
            height: 400,
            closed: false,
            inline: true,
            cache: false,
            href: "${ctx}/framework/user/rightManagePage?userId=" + userId + "&userType=" + userType,
            modal: true,
            buttons: [{
                text: '保存',
                id: 'saveEntityBt',
                iconCls: 'icon-ok',
                handler: function () {
                    var roleIds = getCheckValues("userRole");
                    var rightDictVal = getCheckValues("rightSet");
                    var goodsTypeIds = getCheckValues("goodsCheckSet");
                    if (roleIds == "") {
                        top.$.messager.alert('提示', "请选择相应权限！", 'info');
                    } else {
                        $.ajax({
                            type: "POST",
                            timeout: 20000,
                            url: "${ctx}/framework/user/saveRightData",
                            data: {
                                "userId": userId,
                                "roleIds": roleIds,
                                "rightDictVal": rightDictVal,
                                "goodsTypeIds": goodsTypeIds
                            },
                            success: function (data) {
                                var msn = '' || i18n[''];
                                msn = msn || i18n[data];
                                if (msn == undefined) {
                                    top.$.messager.alert('提示', i18n.serverError, 'info');
                                } else if (msn) {
                                    top.$.messager.alert('提示', msn, 'info', function () {
                                        $('#' + userParamObj.tableId).datagrid('reload');
                                        top.$('#firstLevelDialog').dialog('close');
                                    });
                                }
                            },
                            error: function () {
                                top.$.messager.alert('提示', i18n.requestError, 'error');
                            }
                        });
                    }
                }
            }, {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () {
                    top.$('#firstLevelDialog').dialog('close');
                }
            }]
        }).dialog('open');
    }
    function getCheckValues(input_name) {
        var values = "";
        top.$("input:checkbox[name='" + input_name + "']:checked").each(function (i) {
            if (0 == i) {
                values = $(this).val();
            } else {
                values += ("," + $(this).val());
            }
        });
        return values;
    }

    function formatOper(val, row, index) {
        if (row.registerId == "") {
            <c:choose>
            <c:when test="${not empty isRight}">
            return '<a href="javascript:void(0);" onclick="rightManage(\'' + row.id + '\',\'' + row.type + '\')">权限设置</a>';
            </c:when>
            <c:otherwise>return '';
            </c:otherwise>
            </c:choose>
        } else {
            return "";
        }
    }
</script>
</body>
</html>